package cn.jorian.framework.util;

import cn.jorian.framework.bean.DataBean;
import cn.jorian.framework.config.AppConfig;

import java.util.HashMap;
import java.util.Map;

public class ParamUtil {

    public static Map<String, Object> getParam(DataBean<?> dataBean) {

        //appkey
        AppConfig appConfig = new AppConfig();
        appConfig.setAppKey("A827C64F23323CFF8EA186CF0757E986");
        appConfig.setAppPassword("90%:Q0<tEe");
        //时间戳
        String timestamp = DateTimeUtil.getDateTime("yyyyMMddHHmmss");
        //data json
        String data = GsonUtil.toJson(dataBean);
        //data json base64编码
        String encodeData = Base64Util.encode(data);
        //签名 规则 md5(timestamp+data+AppPassword)
        String sign = MD5Util.md5Hex(timestamp + encodeData + appConfig.getAppPassword());
        //请求参数
        Map<String, Object> param = new HashMap<>();
        param.put("appkey", appConfig.getAppKey());
        param.put("timestamp", timestamp);
        param.put("sign", sign);
        param.put("ver", "1");
        param.put("data", encodeData);
        return param;
    }
}
